package org.springframework.context.annotation;

import lombok.Data;
import lombok.experimental.SuperBuilder;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;

import java.io.IOException;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.function.Predicate;

@SuperBuilder
@Data
public class ConfigurationClassParser {
    private static final Predicate<String> DEFAULT_EXCLUSION_FILTER = className -> (className.startsWith("java.lang.annotation.") || className.startsWith("org.springframework.stereotype."));
    private final Set<ConfigurationClass> configurationClasses = new LinkedHashSet<>();

    private final BeanDefinitionRegistry registry;

    public void parse(Set<BeanDefinitionHolder> configCandidates) {
        for (BeanDefinitionHolder holder : configCandidates) {
            BeanDefinition beanDefinition = holder.getBeanDefinition();
            if (beanDefinition instanceof AbstractBeanDefinition abstractBeanDefinition) {

            }
        }
    }

    protected final void parse(Class<?> clazz,
                               String beanName) throws IOException {
        processConfigurationClass(new ConfigurationClass(clazz, beanName), DEFAULT_EXCLUSION_FILTER);
    }

    private void processConfigurationClass(ConfigurationClass configurationClass,
                                           Predicate<String> filter) {

        if (configurationClasses.contains(configurationClass)) {
            throw new RuntimeException();
        }



    }
}
